n <- 50 # number of trajectories per noise level
noises <- seq(0.2, 3, 0.2)
# Phase shifted
ps <- multi_sims(type = "ps", noises = noises, n = n)
ps
## Time variable value noise
## 1: 0 V1 0.0000000 0
## 2: 1 V1 0.8414710 0
## 3: 2 V1 0.9092974 0
## 4: 3 V1 0.1411200 0
## 5: 4 V1 -0.7568025 0
## ---
## 79996: 95 V50 -0.9858802 3
## 79997: 96 V50 -0.6735795 3
## 79998: 97 V50 0.2580071 3
## 79999: 98 V50 0.9523832 3
## 80000: 99 V50 0.7711425 3
# Phase shifted with trend
pst <- multi_sims(type = "pst", noises = noises, n = n, slope = 0.1)
# Amplitude noise
na <- multi_sims(type = "na", noises = noises, n = n)
plot_sim(ps)
plot_sim(pst)
plot_sim(na)
For each condition, this computes the distance between the average trajectory and each individual trajectory.
cond <- "noise"
ti <- "Time"
mea <- "value"
lab <- "variable"
ps_mean <- dist_mean(data = ps, condition = cond, tcol = ti, measure = mea, label = lab, return.mean = F)
ps_mean
## noise variable euclid_to_mean
## 1: 0 V1 0.000000
## 2: 0 V2 0.000000
## 3: 0 V3 0.000000
## 4: 0 V4 0.000000
## 5: 0 V5 0.000000
## ---
## 796: 3 V46 6.928511
## 797: 3 V47 6.365261
## 798: 3 V48 7.451127
## 799: 3 V49 6.951201
## 800: 3 V50 7.809669
pst_mean <- dist_mean(data = pst, condition = cond, tcol = ti, measure = mea, label = lab, return.mean = F)
na_mean <- dist_mean(data = na, condition = cond, tcol = ti, measure = mea, label = lab, return.mean = F)
For each condition, take each pair of trajectories and compute the correlations between them (Pearson, Spearman and Kendall). In addition it clips the trajectories by comparison with their rolling means: whenever the trajectory is above its rolling mean, set it to 1 otherwise to 0. Finally for each pair of trajectories, the “overlap” metric, represents how often the trajectories of the pair have same value (i.e. 0.5 if complete random, 1 if they fully overlap).
This takes quite a while (partially) because it is implemented with for loops, but is still performed in reasonable time (i.e. a few minutes)
ps_pw <- all_pairwise_stats(data = ps, condition = cond, label = lab, measure = mea, k_roll_mean = 5)
ps_pw
## noise Label1 Label2 Overlap Pearson Spearman Kendall
## 1: 0 V1 V2 1.00 1.0000000 1.0000000 1.0000000
## 2: 0 V1 V3 1.00 1.0000000 1.0000000 1.0000000
## 3: 0 V1 V4 1.00 1.0000000 1.0000000 1.0000000
## 4: 0 V1 V5 1.00 1.0000000 1.0000000 1.0000000
## 5: 0 V1 V6 1.00 1.0000000 1.0000000 1.0000000
## ---
## 19596: 3 V47 V49 0.60 0.3140454 0.3281368 0.2222222
## 19597: 3 V47 V50 0.04 -0.9959261 -0.9967597 -0.9539394
## 19598: 3 V48 V49 0.08 -0.9488995 -0.9511191 -0.8129293
## 19599: 3 V48 V50 0.72 0.6674754 0.6372277 0.4553535
## 19600: 3 V49 V50 0.36 -0.3983772 -0.3933633 -0.2682828
pst_pw <- all_pairwise_stats(data = pst, condition = cond, label = lab, measure = mea, k_roll_mean = 5)
na_pw <- all_pairwise_stats(data = na, condition = cond, label = lab, measure = mea, k_roll_mean = 5)
cor(ps_pw[, 4:7])
## Overlap Pearson Spearman Kendall
## Overlap 1.0000000 0.9888158 0.9905337 0.9983643
## Pearson 0.9888158 1.0000000 0.9997799 0.9903528
## Spearman 0.9905337 0.9997799 1.0000000 0.9920946
## Kendall 0.9983643 0.9903528 0.9920946 1.0000000
cor(pst_pw[, 4:7])
## Overlap Pearson Spearman Kendall
## Overlap 1.0000000 0.9893778 0.9896651 0.9855989
## Pearson 0.9893778 1.0000000 0.9998151 0.9731459
## Spearman 0.9896651 0.9998151 1.0000000 0.9743867
## Kendall 0.9855989 0.9731459 0.9743867 1.0000000
cor(na_pw[, 4:7])
## Overlap Pearson Spearman Kendall
## Overlap 1.0000000 0.9527990 0.9539770 0.9668563
## Pearson 0.9527990 1.0000000 0.9963428 0.9805116
## Spearman 0.9539770 0.9963428 1.0000000 0.9806409
## Kendall 0.9668563 0.9805116 0.9806409 1.0000000
For each condition, count the proportion of trajectories that are lying more than x standard deviation from the mean (conversion to z-score first?).
Get a p-value:
H0: Random overlap would be a binomial process, where at each time point the proba of having an overlap is 0.5 (success)
HA: the proba of overlap is > 0.5
Get a p-value: Assume that they are normally distributed, check that the distributions lies above 0 (t-test)